import { useContext, useEffect, useMemo, useRef, useState } from 'react';
import { Button, Space, message, Modal } from 'antd';
import { QuestionCircleOutlined } from '@ant-design/icons';
import { WorkflowChedkRecord, WorkflowHndTaskBtn, WorkflowNoDefaultTable, WorkflowSwitchModal } from '@/components/WorkflowCommonCopy';
import { changeNumMoneyToChinese, getTenantID, getPosIDs, getUserID, downloadTemplate, printerPDF } from '@/utils';
import { ILoadMapTypeAll } from '@/common';
// import { StampContractModal } from './StampContractModal';
import { TipsErrorModalNew } from '@/components/TipsErrorModalNew';
import { CancelModal } from '@/components/CancelModal';
import { getBaseUrl } from '@/services/urlconst';
import { history } from 'umi';
import { BGflowBusinessType } from '../common/Format';

export const DetailInfoViewBottomBtn: React.FC<any> = ({
  detailInfo,
  position,
  handleSave,
  changeRevoke,
  getDetailRun,
  locationProps,
  revokeReloadCallback,
}) => {
  /** 申请页ref */
  const { confirm } = Modal;

  const closeCurrent = () => {
    confirm({
      title: '关闭',
      icon: <QuestionCircleOutlined />,
      content: '确定要关闭当前页吗？',
      okText: '确定',
      okType: 'primary',
      cancelText: '取消',
      onOk() {
        history.push({
          pathname: locationProps?.state?.returnPathName,
          state: {
            delRouterNameSource: history.location.pathname, //必传,要删除的路由名称
            returnPathName: locationProps?.state?.returnPathName,
          },
        });
      },
      onCancel() {},
    });
  };

  return (
    <>
      <div className="tabsBodyBottomBtn" style={{ display: 'flex', gap: '8px' }}>
        {detailInfo?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1000` &&
        detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_TRANSFER_STATUS}1001` &&
        detailInfo?.createrID == getUserID() &&
        (
          <Button
            type={'primary'}
            danger
            onClick={() => {
              changeRevoke();
            }}
          >
            撤销
          </Button>
        )}
          
        {((locationProps?.state?.pageType !== 'detail') &&(
          (detailInfo?.state == '100124171001' && detailInfo?.checkState == '100199021003') ||
          (detailInfo?.state == '100124171000' && !detailInfo?.checkState)) &&
        detailInfo?.createrID == getUserID())|| locationProps?.state?.pageType === 'add' ? (
          <Button type={'primary'} onClick={() => handleSave(false)}>
            暂存
          </Button>
        ) : null}

        {detailInfo?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1002` ? (
          <Button
            type={'primary'}
            onClick={() => {
              message.success('执行中，请稍后...');
              printerPDF(detailInfo?.workflowURL);
            }}
          >
            打印
          </Button>
        ) : null}

        {position == 'top' &&
        (!detailInfo?.state || (detailInfo?.state == '100124171000' && !detailInfo?.checkState && detailInfo?.createrID == getUserID())) ? (
          <Button type={'primary'} onClick={() => handleSave(true)}>
            提交
          </Button>
        ) : null}

        {position == 'top' && (
          <Button danger onClick={closeCurrent}>
            关闭
          </Button>
        )}

        {/* 流程节点弹框 */}
        {position == 'top' && (
          <WorkflowHndTaskBtn
            flowDetailInfo={detailInfo}
            reloadCallback={() => {
              getDetailRun(detailInfo?.id);
            }}
            revokeDealNum={revokeReloadCallback}
            requestController={'assetApplyTransfer'}
            flowBusinessType={BGflowBusinessType()}
            isAloneSubmit={
              detailInfo?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1003` &&
              detailInfo?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_TRANSFER_STATUS}1001`
            }
          />
        )}
      </div>
    </>
  );
};
